package com.web;

import com.dao.CommentDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/comment/del")
public class CommentDelServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取参数
        String id = req.getParameter("id");

        try {
            // 创建对象并实现删除方法
            new CommentDao().delComment(Integer.parseInt(id));
            // 把信息存到 message 中处理
            req.setAttribute("message", "删除成功");

            // 页面转发到结果页面
            req.getRequestDispatcher("/post/result.jsp").forward(req, resp);
        } catch (Exception e) {
            // 把异常打印到控制台
            e.printStackTrace();
            // 结果输出到控制台
            resp.getWriter().print("删除失败！");
        }
    }
}
